package com.demo.sender.notice.telegram.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author wangfengchen
 */
@Getter
public enum TelegramTypeEnum {

  HTML(1, "html 类型"),
  MARKDOWN(2, "markdown 类型"),

  ;

  private final Integer code;

  /**
   * 描述
   */
  private final String desc;

  TelegramTypeEnum(Integer code, String desc) {
    this.code = code;
    this.desc = desc;
  }

  public static TelegramTypeEnum match(Integer code) {
    Optional<TelegramTypeEnum> target = Arrays.stream(TelegramTypeEnum.values()).filter(item -> code.equals(item.getCode()))
        .findFirst();
    return target.orElse(null);
  }

  public static TelegramTypeEnum match(String name) {
    Optional<TelegramTypeEnum> target = Arrays.stream(TelegramTypeEnum.values()).filter(item -> name.equalsIgnoreCase(item.name()))
        .findFirst();
    return target.orElse(null);
  }

}
